import axios from 'axios';
import { Notify } from 'vant';
import router from '../router';

const req = axios.create();

// 拦截器.请求拦截
req.interceptors.request.use((config) => {
    config.headers.Authorization = localStorage.getItem('TOKEN');
    return config;
});

// 拦截器.响应拦截
req.interceptors.response.use(
    (res) => {
        return res;
    },
    (err) => {
        if (err.response.status === 401) {
            router.push('/login');
        }
    },
);

export default req;
